home *** CD-ROM | disk | FTP | other *** search
/ com!online 2005 May / com_0505_1.iso / opensource / top10 / amc_install.exe / {app} / Scripts / Cinema - PTGate.ifs < prev    next >
Encoding:
Text File  |  2004-09-25  |  6.7 KB  |  225 lines

  1. // GETINFO SCRIPTING
  2. // http://cinema.ptgate.pt/
  3. // Script feito pelo O Guardiπo versπo 1.0 Alpha 3
  4. // 20-09-2004
  5.  
  6.  
  7. (***************************************************
  8.  *  For use with Ant Movie Catalog 3.4.0           *
  9.  *  www.antp.be/software/moviecatalog              *
  10.  *                                                 *
  11.  *  The source code of the script can be used in   *
  12.  *  another program only if full credits to        *
  13.  *  script author and a link to Ant Movie Catalog  *
  14.  *  website are given in the About box or in       *
  15.  *  the documentation of the program               *
  16.  *                                                 *
  17.  *  Please dont remove credits                     *
  18.  *  Reportem os erros para bruno_mga@hotmail.com   *
  19.  ***************************************************)
  20. program PTGate;
  21. const
  22.   BaseAddress = 'http://cinema.ptgate.pt/';
  23.   ManualPictureSelect = True;
  24.   ExternalPictures = False;
  25.   DescriptionToImport = 2;
  26. var
  27.   MovieName: string;
  28.   MovieURL: string;
  29. function HTMLRemove(Value: String): String;
  30. begin
  31.   HTMLDecode(Value);
  32.   HTMLRemoveTags(Value);
  33.   Value := Trim(Value);
  34.   result := Value;
  35. end;
  36.  
  37. procedure AnalyzeFilmPage(Address: String);
  38. var
  39.   Page : TStringList;
  40.   Line, Value : string;
  41.   LineNr, BeginPos, EndPos: Integer;
  42.   AllTitles: TStringList;
  43.   url_imdb:string;
  44.   nome_orig:string;
  45.   nome_trad:string;
  46.   ano:string;
  47.   pais:string;
  48.   genero:string;
  49.   realizac:string;
  50.   Interpretes:string;
  51.   descricao:string;
  52.   capa:string;
  53. begin
  54.   Page := TStringList.Create;
  55.   Address:='http://cinema.ptgate.pt/filme.php?code='+Address;
  56.   Page.Text := GetPage(Address);
  57.   SetField(fieldURL, Address);
  58.  
  59.   //obter nome do filme
  60.   LineNr := FindLine('<td width=300 valign=top>', Page, 0);
  61.   if LineNr<>-1 then
  62.   begin
  63.     Value := Page.GetString(LineNr+2);
  64.     BeginPos := pos('</b><br><b', value);
  65.     nome_orig:=copy(value,6,BeginPos);
  66.                               
  67.    AllTitles := TStringList.Create;
  68.    AllTitles.Add(HTMLRemove(nome_orig));
  69.  
  70.     //por o the no principio do nome
  71.     if pos(', The</b>',nome_orig) <>0 then
  72.     begin
  73.       url_imdb:=HTMLRemove(nome_orig);
  74.       nome_orig:= StringReplace(nome_orig, ', The</b><br>', '');
  75.       nome_orig:=HTMLRemove(nome_orig);
  76.       nome_orig:='The '+Copy(nome_orig,1,length(nome_orig)-5);
  77.       AllTitles.Add(nome_orig);
  78.     end;
  79.  
  80.     nome_orig:=HTMLRemove(nome_orig);
  81.     SetField(fieldOriginalTitle, nome_orig);
  82.   end;
  83.  
  84.   //obter nome traduzido
  85.   BeginPos := pos('<b class=subtitle>', value)+18;
  86.   value:= Copy(value,BeginPos,length(value));
  87.   EndPos := pos('</b>',value);
  88.   nome_trad:=Copy(value,1,EndPos);
  89.   nome_trad:=HTMLRemove(nome_trad);
  90.   SetField(fieldTranslatedTitle, nome_trad);
  91.   value:=Copy(value,EndPos,length(value));
  92.  
  93.   //ano
  94.   BeginPos := pos('<br><br><b>', value)+22;
  95.   value:= Copy(value,BeginPos,length(value));
  96.   EndPos := pos('<br><br><b>',value);
  97.   ano:=Copy(value,1,EndPos);
  98.   ano:=HTMLRemove(ano);
  99.   SetField(fieldYear, ano);
  100.   value:=Copy(value,EndPos,length(value));
  101.  
  102.   //paφs
  103.   BeginPos := pos('<br><b>paφs</b><br>', value)+19;
  104.   value:= Copy(value,BeginPos,length(value));
  105.   EndPos := pos('<br><br><b>',value);
  106.   pais:=Copy(value,1,EndPos);
  107.   pais:=HTMLRemove(pais);
  108.   SetField(fieldCountry, pais);
  109.   value:=Copy(value,EndPos,length(value));
  110.  
  111.   //gΘnero
  112.   BeginPos := pos('<br><b>gΘnero</b><br>', value)+21;
  113.   value:= Copy(value,BeginPos,length(value));
  114.   EndPos := pos('<br><br><b>',value);
  115.   genero:=Copy(value,1,EndPos);
  116.   genero:=HTMLRemove(genero);
  117.   SetField(fieldCategory, genero);
  118.   value:=Copy(value,EndPos,length(value));
  119.  
  120.  //realizaτπo
  121.   BeginPos := pos('<br><br><b>realizaτπo</b><br>', value)+29;
  122.   value:= Copy(value,BeginPos,length(value));
  123.   EndPos := pos('<br><br><b>',value);
  124.   realizac:=Copy(value,1,EndPos);
  125.   realizac:=HTMLRemove(realizac);
  126.   SetField(fieldDirector, realizac);
  127.   value:=Copy(value,EndPos,length(value));
  128.  
  129.   //IntΘrpretes
  130.   BeginPos := pos('<br><br><b>intΘrpretes</b><br>', value)+30;
  131.   value:= Copy(value,BeginPos,length(value));
  132.   EndPos := pos('<br><br><b>',value);
  133.   Interpretes:=Copy(value,1,EndPos);
  134.   Interpretes:= StringReplace(Interpretes, '<br>', ', ');
  135.   Interpretes:=HTMLRemove(Interpretes);
  136.   SetField(fieldActors, Interpretes);
  137.   value:=Copy(value,EndPos,length(value));
  138.   
  139.   //descriτπo
  140.   BeginPos := pos('</a><br><br><b>sinopse</b><br>', value)+30;
  141.   value:= Copy(value,BeginPos,length(value));
  142.   EndPos := pos('<br><br><b>',value);
  143.   EndPos:=Length(value);
  144.   descricao:=Copy(value,1,EndPos);
  145.   descricao:=HTMLRemove(descricao);
  146.   SetField(fieldDescription, descricao);
  147.  
  148.   //capa
  149.   LineNr := FindLine('width=100 height=150>', Page, 0);
  150.   Value := Page.GetString(LineNr);
  151.   BeginPos:=pos('<img src=',value)+10;
  152.   EndPos:=pos(' width=100 height=150>',value)-1;
  153.   value:=Copy(value,BeginPos,EndPos-BeginPos);
  154.   value:='http://cinema.ptgate.pt/'+value;
  155.   GetPicture(Value, False);
  156. end;
  157.  
  158.  
  159.  
  160. function FindLine(Pattern: string; List: TStringList; StartAt: Integer): Integer;
  161. var
  162.   i: Integer;
  163. begin
  164.   result := -1;
  165.   if StartAt < 0 then
  166.     StartAt := 0;
  167.   for i := StartAt to List.Count-1 do
  168.     if Pos(Pattern, List.GetString(i)) <> 0 then
  169.     begin
  170.       result := i;
  171.       Break;
  172.     end;
  173. end;
  174.  
  175. procedure AnalyzePage(Address: string);
  176. var
  177.   Page: TStringList;
  178.   LineNr, StartPos, EndPos: Integer;
  179.   Line: string;
  180.   x:integer;
  181.   MovieAddress, findMovieName,linedown : string;
  182.   guardar,url, nome_filme:string;
  183. begin
  184.   PickTreeClear;
  185.   Page := TStringList.Create;
  186.   Page.Text := GetPage(Address);
  187.  
  188.   if (pos('Nπo foram encontrados filmes ou pessoas que satisfaτam a sua pesquisa.', Page.Text)<>-1) then   //se existe
  189.   begin
  190.       LineNr := FindLine('filme.php?code=', Page, LineNr);
  191.       Line := Page.GetString(LineNr);
  192.     repeat
  193.         StartPos := pos('filme.php?code=', Line)+15;
  194.         if StartPos=15 then break;
  195.  
  196.         guardar:=Copy(line,StartPos+1,9999);
  197.         line:=Copy(line,StartPos,9999);    
  198.         StartPos := pos('>',line)+1;
  199.         url:=(copy(line,1,StartPos-3));
  200.         EndPos := pos('</a>',line)-1;
  201.         line := copy(Line, StartPos, EndPos - StartPos+1);
  202.           nome_filme:=line;
  203.         PickTreeAdd(nome_filme, url);
  204.         line:=guardar;
  205.         
  206. until (nome_filme='');
  207.  
  208.     if PickTreeExec(Address) then begin
  209.       AnalyzeFilmPage(Address);
  210.     end;
  211.     Page.Free;
  212.   end;
  213.   DisplayResults;
  214. end;
  215. begin
  216.   PickListClear;
  217.   MovieName := GetField(fieldOriginalTitle);
  218.   if Input('Importar do cinema.ptgate.pt', 'Escreva o nome do filme:', MovieName) then begin
  219.   //espaτo nπo sπo permitidos
  220.   MovieName := StringReplace(MovieName, ' ', '%20');
  221.   AnalyzePage('http://cinema.ptgate.pt/pesquisa.php?pesquisa='+MovieName);
  222.   end;
  223. end.
  224.  
  225.